package com.gongj.rabbit.topic;

import com.gongj.rabbit.utils.RabbitMQUtil;
import com.rabbitmq.client.*;

import java.io.IOException;

public class Customer {

    public static void main(String[] args) throws IOException {
        Connection conn = RabbitMQUtil.createConn();
        Channel channel = conn.createChannel();
        String exchangName = "topics";
        //声明topic交换机
        channel.exchangeDeclare(exchangName,BuiltinExchangeType.TOPIC);

        String queue = channel.queueDeclare().getQueue();
        channel.queueBind(queue,exchangName,"user.*");
        channel.basicConsume(queue,true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1：" + new String(body));
            }
        });
    }

}

